﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace EasySite.Models
{
    public partial class PageCategory
    {
        private readonly List<PageCategory> _children = new List<PageCategory>();
        public List<PageCategory> Children
        {
            get { return _children; }
        }

        public string[] Roles { get; set; }

        public bool Accesible
        {
            get
            {
                if (this.NeedAuthentication == null)
                {
                    return true;
                }
                var context = HttpContext.Current;
                if (context.Request.IsAuthenticated)
                {
                    if (this.NeedAuthentication.Value)
                    {
                        return this.Roles.Any(role => context.User.IsInRole(role));
                    }
                    return false;
                }
                return !this.NeedAuthentication.Value;
            }
        }
    }
}
